<template>
  <div id="image-file">
    <img :src="imgurl" id="div_img">
  </div>
</template>

<script>
  import { postDataToServer } from '../../assets/js/post.js'

  export default {
    name: 'imagefile',
    props: ['imagedata', 'authority'],//authority.id为新闻的ID,key在post.js找到对应的接口
    data () {
      return {
        fileauth: false,
        fileexpires: '',
        filesign: '',
        imgurl: '',
      }
    },
    created () {
      this.getUrl(this.imagedata)
    },
    methods: {
      getUrl (val) {
        let _this = this
        let params = new Object()
        if (!val) {
          return
        }
        params.file_md5 = val
        params.id = this.authority.id
        postDataToServer(this.authority.key, params)
          .then((data) => {
            if (data.status == 0) {
              this.imgurl = data.download_url
            }
            else {
              this.$message({
                message: '图片链接失效',
                type: 'error'
              })
            }
          })
      },
    },
    watch: {
      imagedata: function (val, oldVal) {
        this.getUrl(val)
      }
    }
  }
</script>

<style scoped>
  #image-file {
    width: 100%;
    height: 100%;
  }

  #div_img {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }
</style>
